package com.furongji.education.controller.admin;


import com.furongji.common.result.Result;
import com.furongji.education.domain.po.Section;
import com.furongji.education.service.SectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author furongji
 * @since 2025-05-19
 */
@Tag(name = "课程小节管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/courses")
public class SectionAdminController {

    private final SectionService sectionService;

    @Operation(summary = "添加小节")
    @PostMapping("/addSection")
    public Result addSection(@RequestBody Section section) {
        boolean flag = sectionService.save(section);
        if (flag) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    //修改小节
    @Operation(summary = "修改小节")
    @PutMapping("/updateSection")
    public Result updateSection(@RequestBody Section section) {
        boolean flag = sectionService.updateById(section);
        if (flag) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @Operation(summary = "删除小节")
    @DeleteMapping("/delSection/{id}")
    public Result delSection(@PathVariable String id) {
        boolean flag = sectionService.removeSectionById(id);
        if (flag) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @Operation(summary = "根据id查询小节")
    @GetMapping("/getSection/{id}")
    public Result getSection(@PathVariable String id) {
        Section section = sectionService.getById(id);
        return Result.success(section);
    }
}
